import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:gold/model/address_model.dart';
import 'package:gold/model/gold_recover_order_model.dart';
import 'package:gold/model/goods_detail_model.dart';
import 'package:gold/model/order_model.dart';
import 'package:gold/ui/goods/goods_detail_page.dart';
import 'package:gold/ui/goods/goods_order_page.dart';
import 'package:gold/ui/home/invest/gold_invest_detail_page.dart';
import 'package:gold/ui/home/invest/gold_invest_order_page.dart';
import 'package:gold/ui/home/invest/gold_invest_page.dart';
import 'package:gold/ui/home/quotes/real_time_quotes_page.dart';
import 'package:gold/ui/home/rank/rank_content_viewmodel.dart';
import 'package:gold/ui/home/rank/rank_history_page.dart';
import 'package:gold/ui/home/rank/rank_page.dart';
import 'package:gold/ui/home/rank/rank_rules_page.dart';
import 'package:gold/ui/home/recover/gold_recover_page.dart';
import 'package:gold/ui/home/recover/recover_success_page.dart';
import 'package:gold/ui/home/recover/shop_list_page.dart';
import 'package:gold/ui/integralmall/integral_goods_page.dart';
import 'package:gold/ui/integralmall/integral_mall_page.dart';
import 'package:gold/ui/integralmall/integral_order_page.dart';
import 'package:gold/ui/login/password_page.dart';
import 'package:gold/ui/my/address/address_page.dart';
import 'package:gold/ui/my/address/new_address_page.dart';
import 'package:gold/ui/my/fund/fund_details_page.dart';
import 'package:gold/ui/my/integral/integral_detail_page.dart';
import 'package:gold/ui/my/invite/invite_page.dart';
import 'package:gold/ui/my/invoice/invoice_page.dart';
import 'package:gold/ui/my/order/apply_invoice_page.dart';
import 'package:gold/ui/my/order/apply_refund_page.dart';
import 'package:gold/ui/my/order/appraise_page.dart';
import 'package:gold/ui/my/order/authorization_collect_page.dart';
import 'package:gold/ui/my/order/logistics_page.dart';
import 'package:gold/ui/my/order/my_order_page.dart';
import 'package:gold/ui/my/order/order_detail_page.dart';
import 'package:gold/ui/my/order/recover/offline_detail_page.dart';
import 'package:gold/ui/my/order/recover/online_detail_page.dart';
import 'package:gold/ui/my/order/recover/recover_logistics_page.dart';
import 'package:gold/ui/my/order/recover/recover_order_page.dart';
import 'package:gold/ui/my/settings/express/express_company_page.dart';
import 'package:gold/ui/my/settings/express/set_express_page.dart';
import 'package:gold/ui/my/order/refund_detail_page.dart';
import 'package:gold/ui/my/order/refund_page.dart';
import 'package:gold/ui/my/settings/avatar/avatar_page.dart';
import 'package:gold/ui/my/settings/name/name_page.dart';
import 'package:gold/ui/my/settings/phone/phone_page.dart';
import 'package:gold/ui/my/settings/profile_page.dart';
import 'package:gold/ui/my/settings/settings_page.dart';
import 'package:gold/ui/my/shop/commission/commission_details_page.dart';
import 'package:gold/ui/my/shop/customer/customer_page.dart';
import 'package:gold/ui/my/shop/my_shop_page.dart';
import 'package:gold/ui/my/shop/order/shop_order_page.dart';
import 'package:gold/ui/my/withdrawal/withdrawal_details_page.dart';
import 'package:gold/ui/my/withdrawal/withdrawal_page.dart';
import 'package:gold/ui/my/withdrawal/withdrawal_succes_page.dart';
import 'package:gold/ui/pay/pay_page.dart';
import 'package:gold/ui/pay/pay_success_page.dart';
import 'package:gold/ui/root/root_page.dart';
import 'package:gold/ui/rules/rules_page.dart';
import 'package:gold/utils/size_extension.dart';
import 'package:gold/utils/xfg_color.dart';
import 'package:gold/widgets/video_play_page.dart';
import 'package:gold/widgets/xfg_text.dart';

/// 描述:
/// 
/// @Author tangzhentao
///  @CreatedTime 21:01 2022/6/17
/// 

class Routes {
  static const String root = "/";
  static const String loginPassword = "/password";
  static const String settings = "/settings";
  static const String settingsPhone = "/settings/phone";
  static const String settingsPassword = "/settings/password";
  static const String settingsProfile = "/settings/profile";
  static const String settingsProfileName = "/settings/profile/name";
  static const String settingsProfileAvatar = "/settings/profile/avatar";
  static const String settingsSetExpress = "/settings/setExpress";
  static const String settingsSetExpressCompany = "/settings/setExpress/company";
  static const String rank = "/rank";
  static const String rankRules = "/rank/rules";
  static const String rankHistory = "/rank/history";
  static const String realTimeQuotes = "/realTimeQuotes";
  static const String goodsDetail = "/goodsDetail";
  static const String goodsOrder = "/goodsDetail/order";
  static const String integrationMall = "/integrationMall";
  static const String integralGoods = "/integrationMall/goods";
  static const String integralGoodsOrder = "/integrationMall/goods/Order";
  static const String goldInvest = "/goldInvest";
  static const String goldInvestDetail = "/goldInvest/detail";
  static const String goldInvestDetailOrder = "/goldInvest/detail/order";
  static const String goldRecover = "/goldRecover";
  static const String goldRecoverSuccess = "/goldRecover/success";
  static const String goldRecoverShopList = "/goldRecover/shopList";
  static const String myInvite = "/my/invite";
  static const String myAddress = "/my/address";
  static const String myAddressNew = "/my/address/new";
  static const String myIntegral = "/my/integral";
  static const String myInvoice = "/my/invoice";
  static const String myFundDetails = "/my/fundDetails";
  static const String myWithdrawal = "/my/withdrawal";
  static const String myWithdrawalDetails = "/my/withdrawal/details";
  static const String myWithdrawalSuccess = "/my/withdrawal/success";
  static const String myOrder = "/my/order";
  static const String myOrderDetail = "/my/order/detail";
  static const String myOrderRecover = "/my/orderRecover";
  static const String myOrderRecoverOnlineDetail = "/my/orderRecover/onlineDetail";
  static const String myOrderRecoverOfflineDetail = "/my/orderRecover/offlineDetail";
  static const String myOrderRecoverLogistics = "/my/orderRecover/logistics";
  static const String myOrderAuthorizationCollect = "/my/order/authorizationCollect";
  static const String myOrderLogistics = "/my/order/logistics";
  static const String myOrderAppraise = "/my/order/appraise";
  static const String myOrderApplyInvoice = "/my/order/applyInvoice";
  static const String myOrderApplyRefund = "/my/order/applyRefund";
  static const String myOrderRefundApplying = "/my/order/refundApplying";
  static const String myOrderRefundApplyingDetail = "/my/order/refundApplying/detail";
  static const String myShop = "/my/shop";
  static const String myShopCommissionDetails = "/my/shop/commissionDetails";
  static const String myShopCustomer = "/my/shop/customer";
  static const String myShopOrder = "/my/shop/order";
  static const String pay = "/pay";
  static const String rules = "/rules";
  static const String paySuccess = "/pay/success";
  static const String videoPlay = "/videoPlay";
}

CupertinoPageRoute<T> onWsGenerateRoute<T>(RouteSettings settings) {
  final Widget page;
  switch(settings.name) {
    case Routes.root:
      page = const RootPage();
      break;
    case Routes.loginPassword:
      page = PasswordPage(isLogin: true);
      break;
    case Routes.settings:
      page = const SettingsPage();
      break;
    case Routes.settingsPhone:
      page = const PhonePage();
      break;
    case Routes.settingsPassword:
      page = PasswordPage(isLogin: false);
      break;
    case Routes.settingsProfile:
      page = const ProfilePage();
      break;
    case Routes.settingsProfileName:
      page = const NamePage();
      break;
    case Routes.settingsProfileAvatar:
      page = const AvatarPage();
      break;
    case Routes.settingsSetExpress:
      final map = settings.arguments as Map<String, dynamic>;
      page = SetExpressPage(orderId: map['orderId'], isShopOrder: (map['isShopOrder'] as bool?)?? false);
      break;
    case Routes.settingsSetExpressCompany:
      page = const ExpressCompanyPage();
      break;
    case Routes.realTimeQuotes:
      page = const RealTimeQuotesPage();
      break;
    case Routes.rank:
      page = RankPage();
      break;
    case Routes.rankHistory:
      page = RankHistoryPage(type: settings.arguments as PoolType);
      break;
    case Routes.rankRules:
      page = const RankRulesPage();
      break;
    case Routes.integrationMall:
      page = const IntegrationMallPage();
      break;
    case Routes.goodsDetail:
      page = GoodsDetailPage(goodsId: settings.arguments as int);
      break;
    case Routes.goodsOrder:
      page = GoodsOrderPage(goods: settings.arguments as GoodsDetailModel);
      break;
    case Routes.integralGoods:
      page = IntegralGoodsPage(goodsId: settings.arguments as int);
      break;
    case Routes.integralGoodsOrder:
      final map = settings.arguments as Map<String, dynamic>;
      page = IntegralOrderPage(number: map['number'], goods: map['goods']);
      break;
    case Routes.goldInvest:
      page = const GoldInvestPage();
      break;
    case Routes.goldInvestDetail:
      page = GoldInvestDetailPage(goodsId: settings.arguments as int);
      break;
    case Routes.goldInvestDetailOrder:
      page = GoldInvestOrderPage(goods: settings.arguments as GoodsDetailModel);
      break;
    case Routes.goldRecover:
      page = GoldRecoverPage(price: settings.arguments as double);
      break;
    case Routes.goldRecoverSuccess:
      final map = settings.arguments as Map<String, dynamic>;
      page = RecoverSuccessPage(id: map['id'], type: map['type']);
      break;
    case Routes.goldRecoverShopList:
      page = const ShopListPage();
      break;
    case Routes.myInvite:
      page = const InvitePage();
      break;
    case Routes.myAddress:
      page = AddressPage(isPicker: settings.arguments as bool?);
      break;
    case Routes.myAddressNew:
      page = NewAddressPage(address: settings.arguments as AddressModel?);
      break;
    case Routes.myIntegral:
      page = const IntegralDetailPage();
      break;
    case Routes.myOrder:
      final data = settings.arguments as Map<String, dynamic>;
      page = MyOrderPage(orderType: data['orderType'],  orderStatus: data['orderStatus']);
      break;
    case Routes.myOrderRecover:
      page = RecoverOrderPage();
      break;
    case Routes.myOrderRecoverOnlineDetail:
      page = OnlineDetailPage(order: settings.arguments as GoldRecoverOrderModel);
      break;
    case Routes.myOrderRecoverOfflineDetail:
      page = OfflineDetailPage(order: settings.arguments as GoldRecoverOrderModel);
      break;
    case Routes.myOrderRecoverLogistics:
      final map = settings.arguments as Map<String, dynamic>;
      page = RecoverLogisticsPage(isShip: map['isShip'], weight: map['weight'], express: map['express']);
      break;
    case Routes.myInvoice:
      page = const InvoicePage();
      break;
    case Routes.myFundDetails:
      page = const FundDetailsPage();
      break;
    case Routes.myWithdrawal:
      page = const WithdrawalPage();
      break;
    case Routes.myWithdrawalSuccess:
      page = const WithdrawalSuccessPage();
      break;
    case Routes.myWithdrawalDetails:
      page = const WithdrawalDetailsPage();
      break;
    case Routes.myOrderDetail:
      final map = settings.arguments as Map<String, dynamic>;
      page = OrderDetailPage(orderType: map['orderType'], orderId: map['orderId']);
      break;
    case Routes.myOrderAuthorizationCollect:
      page = AuthorizationCollectPage(order: settings.arguments as OrderModel);
      break;
    case Routes.myOrderLogistics:
      final map = settings.arguments as Map<String, dynamic>;
      page = LogisticsPage(product: map['product'], address: map['address'], express: map['express']);
      break;
    case Routes.myOrderAppraise:
      final map = settings.arguments as Map<String, dynamic>;
      page = AppraisePage(orderId: map['id'], productId: map['productId'], product: map['product']);
      break;
    case Routes.myOrderApplyInvoice:
      page = ApplyInvoicePage(orderId: settings.arguments as int);
      break;
    case Routes.myOrderApplyRefund:
      page = ApplyRefundPage(order: settings.arguments as OrderModel);
      break;
    case Routes.myOrderRefundApplying:
      final map = settings.arguments as Map<String, dynamic>;
      page = RefundPage(orderId: map['orderId'], price: map['price'], points: map['points'], productLogo: map['productLogo'], productName: map['productName']);
      break;
    case Routes.myOrderRefundApplyingDetail:
      final map = settings.arguments as Map<String, dynamic>;
      page = RefundDetailPage(refund: map['refund'], logs: map['logs']);
      break;
    case Routes.myShop:
      page = const MyShopPage();
      break;
    case Routes.myShopCommissionDetails:
      page = const CommissionDetailsPage();
      break;
    case Routes.myShopCustomer:
      page = const CustomerPage();
      break;
    case Routes.rules:
    final map = settings.arguments as Map<String, dynamic>;
      page = RulesPage(config: map['config'], title: map['title']);
      break;
    case Routes.myShopOrder:
      page = ShopOrderPage(orderStatus: settings.arguments as String?);
      break;
    case Routes.pay:
      final map = settings.arguments as Map<String, dynamic>;
      page = PayPage(type: map['type'], id: map['id'], amount: map['amount'], createAt: map['createAt'], fromOrder: map['fromOrder']?? false);
      break;
    case Routes.paySuccess:
      final map = settings.arguments as Map<String, dynamic>;
      page = PaySuccessPage(type: map['type'], id: map['id'], fromOrder: map['fromOrder']?? false);
      break;
    case Routes.videoPlay:
      page = VideoPlayPage(url: settings.arguments as String);
      break;
    default:
      page = Scaffold(
          extendBody: true,
          backgroundColor: XfgColor.white,
          body: Center(child: XfgText('未知页面', fontSize: 48.xsp))
      );
      break;
  }
  return CupertinoPageRoute<T>(builder: (_) => page, settings: RouteSettings(name: settings.name));
}